<template>
  <div>
    <div class="content">
      <el-form :model="loginForm" :rules="rules" ref="loginForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="用户名" prop="userName">
          <el-input v-model="loginForm.userName"></el-input>
        </el-form-item>
        
        <el-form-item label="密码"  prop="password">
            <el-input
                    @keyup.enter.native="handleLogin"
                    :type="passwordType"
                    v-model="loginForm.password"
                    auto-complete="off"
                    placeholder="请输入密码">
            <i class="el-icon-view el-input__icon"
              slot="suffix"
              @click="showPassword"></i>
            <i slot="prefix"
              class="icon-mima"></i>
          </el-input>
        </el-form-item>
        <el-form-item >
          <el-button type="text"  @click="gotoRegister">立即注册</el-button>
          <el-button type="primary" @click="submitForm('loginForm')">立即登录</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div style="text-align: center; padding-bottom: 50px; font-size: 14px">
      XXXX <span style="color: #666666"> 提供技术支持</span>
    </div>
  </div>
</template>

<script>
import {exportSysCustomUserInfoExcel,saveOrUpdateSysCustomUserInfo,saveOrUpdateSysCustomUserInfoList,saveSysCustomUserInfo,saveSysCustomUserInfoList,deleteSysCustomUserInfo,querySysCustomUserInfo,querySysCustomUserInfoListPage,updateSysCustomUserInfo,deleteSysCustomUserInfoList} from '@/api/system/sysCustomUserInfoApi';
import { mapGetters } from 'vuex';
import { reqCommonMsg } from '@/util/reqCommonMsg';
import { regionData, CodeToText } from 'element-china-area-data';
import { getToken } from '@/util/auth';
import { Base64 } from 'js-base64';
export default {
  data() {
    return {
      // 登录表单
      passwordType: 'password',
      loginForm: {
        userName: '',
        password: ''
      },
      rules: {
        userName: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, max: 8, message: '请输入在 6 到 8 位长度密码！', trigger: 'blur' }
        ]
      },
      // 请求参数区
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      reqParams: {
        singleBody: {},
        listBody: [{}],
        sqlCondition: [],
        orderRule: [],
        currentPage: 1,
        pageSize: 10,
      },
      commonData: null,
      conditions: [],
      orderRules: [],
      singleBody: {},
    };
  },
  computed: {
    ...mapGetters([
      'website',
      'orgTree',
      'genOrgTree',
      'userInfo',
      'permission',
      'projectInfo',
    ]),
  },
  methods: {
    /**
     * 提交
     */
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          const loading = this.$loading({
            lock: true,
            text: '登录中,请稍后。。。',
            spinner: 'el-icon-loading'
          });
          this.reqParams = {
            username: 'DOOL1001=custom=password=pc=' + this.loginForm.userName+'@@password',
            // username: 'pwd='+this.tenantId+'='+this.loginForm.username+'=admin',
            //移动端登录 username: 'LEARN1001=custom=password=' + this.vx_provider + '=' + this.loginForm.userName,
            password: this.$toolUtil.encodeMd5(this.loginForm.password),
            tenantId: 'DOOL1001'
          } 
          
          this.$store.dispatch('LoginByUsername', this.reqParams).then((data) => {
            localStorage.setItem('tenantId', data.additionalInformation.userInfo.tenantId);
            //获取租户及用户设置 
            this.$console.log('===data====',data)
            loading.close()
            this.$router.push({ path: '/website/register'});
          }).catch(() => {
            loading.close()
          });
        }
      });
    },
   
    /**
     * 显示密码
     */
    showPassword() {
      this.passwordType === ''
        ? (this.passwordType = 'password')
        : (this.passwordType = '');
    },
    /**
     * 跳转到注册
     */
    gotoRegister(){
      this.$router.push({ path: '/website/register'});
    }
  },
  created() {
    // let urlParam = this.$toolUtil.UrlSearch();
    // if (urlParam.qn) {
    //   this.questionSheetId = Base64.decode(urlParam.qn.replace(/%3D/g, '='));
    // } else {
    //   alert('访问无效');
    // }
  },
  mounted() {
    
  },
};
</script>
<style  lang="scss">
html,
body,
#app {
  height: 100%;
  overflow: auto;
  margin: 0;
  padding: 0;
  background: #edf2f7 !important;
}
.content {
  margin: 0 auto;
  width: 500px;
  margin-bottom: 50px;
  margin-top: 100px;
  padding: 30px;
  background-color: #ffffff;
}

</style>
